﻿<{capture name="header"}>
<link href="../app/ome/statics/ome.css" rel="stylesheet" type="text/css">
  <link href="statics/singlepage.css" rel="stylesheet" type="text/css">
<{/capture}>



<script type="text/javascript">
var count = <{$count}>;
var already = <{$verify_num}>;
var remain = <{$remain}>;
var define = <{$conf}>;
var tmpDiv = '';

$("bn").addEvent('keydown',function(e){
    if (e.key == 'enter'){
        check();
        return false;
    }
});

//<!--FUNCTION_CHECK_BEGIN-->
function check(){
    var bn = $("bn").value;
    if (bn != ''){
        $("tmp_bn").value = bn;
        if ($("_"+bn)){
            if (tmpDiv) tmpDiv.set('styles',{'backgroundColor':''});
            tmpDiv = $("_"+bn);
            tmpDiv.set('styles',{'backgroundColor':'#D8D8D8'});
        }
        if (!$(bn)){
                $('goodsMsg').style.display = 'none';
            $('mess').set('text','发货单中没有条形码为'+bn+'的商品！');
            $('mess').setStyle('color', 'red');
            $("bn").value = '';
            $("bn").focus();
            return false;
        }
            var name = $(bn+"_name").get('text');
        var num = parseInt($(bn+"_num").get('text'));
        var all = parseInt($(bn+"_all").get('text'));
        if (num < all){
            num++;
            $(bn+"_num").set('text',num);
                $('number_' + bn).value = num;
            already++;
            $('number').value = already;

                //新增产品信息显示
                $('goodsMsg').style.display = '';
                $('msgGoodsName').set('html', name);
                $('msgTotalNum').set('html', all-num);
                $('msgFinshNum').set('html', num);
                $('bn').value = '';
                $('bn').focus();
                if (num < all){
                    //$("ipt_num").setStyle('display','');
                    //$("ipt_title").setStyle('display','');
                    //$("ipt_num").focus();
                    if(define < all){
	                    $("ipt_num").value = all-num;
	                    $('inputNumDiv').style.display = '';
	                    $('goodsMsg').style.height ='60px';
	                    $(bn+"_name").set('styles', {'color':'red'});
                    }else{
                        $('inputNumDiv').style.display = 'none';
                        $('goodsMsg').style.height = '32px';
                        $(bn+"_name").set('styles', {'color':'#eeeeee'});
                    }
                } else {
                    $('inputNumDiv').style.display = 'none';
                    $('goodsMsg').style.height = '32px';
                    $(bn+"_name").set('styles', {'color':'#eeeeee'});
                    //$('goodsMsg').style.padding-top = '15px';
            }
        }else {
            //alert("此货品的数据已校验完成，如果本次为扫描为正常扫描，请返回重新操作！如果非正常扫描，请确认后继续操作");
                $('goodsMsg').style.display = 'none';
            $('mess').set('text','此条形码为'+bn+'的商品已扫描完成！如果确认未扫描过，请返回重新进行操作，否则请继续');
            $('mess').setStyle('color', 'red');
            $("bn").value = '';
            $("bn").focus();
            return false;
        }
    }else {
        if (tmpDiv) tmpDiv.set('styles',{'backgroundColor':''});
        $("bn").focus();
    }
    $("bn").value = '';
    remain = count-already;

        var tmp = "需要扫描 <font color='#333333'>"+count+"</font> 个    已扫描 <font color='green'>"+already+"</font> 个    未扫描 <b><font color='red'>"+remain+"</font></b>个";
        //$("mess").set('innerHTML',tmp);
        $("mess").innerHTML = tmp;
    $('mess').setStyle('color', 'black');
    if ($('count').value == $('number').value){
        $("return").value = 'OK';
        $("logi_no").focus();
        $("form1").fireEvent('submit',{stop:function(){}});
    }
    return false;
}
//<!--FUNCTION_CHECK_END-->


function checkin(){
    /*var re = $('return').value;
    if (re == 'OK'){
        $('form1').fireEvent('submit',{stop:function(){}});
        return true;
    }
    var msg = "校验未完成,请完成校验后操作";
    $('mess').set('text',msg).setStyle('color', 'red');
    return false;*/
    $('form1').fireEvent('submit',{stop:function(){}});
    if ($('count').value == $('number').value){
        return true;
    } else {
        return false;
    }
}
    $("ipt_num").addEvent('blur',function(event){
    reset_dis_num();
});
    $("ipt_num").addEvent('keydown',function(event){
    if(event.key=='enter'){
            var tt = $("ipt_num").value;
        if (tt == ''){
            reset_dis_num();
            $("bn").focus();
            return false;
        }else {
            if (isNaN(tt)){
                    $("messs").set('text','请输入本次扫描货品的数字')
               return false;
            }
        }
        var tmp = $("tmp_bn").value;
        var ipn = parseInt(tt);
            var name = $(tmp+"_name").get('text');
        var num = parseInt($(tmp+"_num").get('text'));
        var all = parseInt($(tmp+"_all").get('text'));
        if (num < all){
            if (num+ipn > all){
                $("messs").set('text','填写的数量大于未扫描数');
                return false;
            }
            num = num+ipn;
            $(tmp+"_num").set('text',num);
                $('number_' + tmp).value = num;
            already = already+ipn;
            $('number').value = already;
            remain = count-already;

                //新增产品信息显示
                $('goodsMsg').style.display = '';
                $('msgGoodsName').set('html', name);
                $('msgTotalNum').set('html', all-num);
                $('msgFinshNum').set('html', num);
                $('bn').value = '';
                $('bn').focus();
                if (num < all){
                    //$("ipt_num").setStyle('display','');
                    //$("ipt_title").setStyle('display','');
                    //$("ipt_num").focus();
                    $("ipt_num").value = all-num;
                    $('inputNumDiv').style.display = '';
                    $('goodsMsg').style.height ='60px';
                    $(tmp+"_name").set('styles', {'color':'red'});
                } else {
                    $('inputNumDiv').style.display = 'none';
                    $('goodsMsg').style.height = '32px';
                    $(tmp+"_name").set('styles', {'color':'#eeeeee'});
                    //$('goodsMsg').style.padding-top = '15px';
                }

                var tmp = "需要扫描 <font color='#333333'>"+count+"</font> 个    已扫描 <font color='green'>"+already+"</font> 个    未扫描 <b><font color='red'>"+remain+"</font></b>个";
                //$("mess").set('text',tmp);
                $("mess").innerHTML = tmp;
            if ($('count').value == $('number').value){
                $("return").value = 'OK';
                reset_dis_num();
                $("logi_no").focus();
                $("form1").fireEvent('submit',{stop:function(){}});
            }else {
                reset_dis_num();
            }
        }else {
            if ($('count').value == $('number').value){
                $("return").value = 'OK';
                reset_dis_num();
                $("logi_no").focus();
                $("form1").fireEvent('submit',{stop:function(){}});
            }
            reset_dis_num();
        }
        return false;
    }
});
$("logi_no").addEvent('keydown',function(e){
    if (e.key=="enter"){
        return checkin();
    };
});

function reset_dis_num(){
        //$("ipt_num").setStyle('display','none');
        //$("ipt_title").setStyle('display','none');
    if (tmpDiv) tmpDiv.set('styles',{'backgroundColor':''});
    $("bn").focus();
}
reset_dis_num();


$('form1').store('target',{
    onRequest:function(){
       $('backbtn').set('disabled', 'true');
       $('logi_no').set('disabled', 'true');
       $('logi_no').getElements('span')[1].set('text','提交中');
    },
    onComplete:function(jsontext){
       var json = Json.evaluate(jsontext);
       if (typeof(json.error) != 'undefined'){
           $('backbtn').set('disabled', '');
           $('logi_no').set('disabled', '');
           $('logi_no').getElements('span')[1].set('text','提交');
       }else{
           if (json.success.indexOf('校验完成') >= 0){
               $('backbtn').set('disabled', 'true');
           }else {
               $('backbtn').set('disabled', '');
           }
           $('logi_no').set('disabled', '');
           $('logi_no').getElements('span')[1].set('text','提交');
       }

    }
});

(function(){
    new Request({url:'index.php?ctl=adminpanel',onComplete:function(rs){
    }}).send();
}).periodical(600000);

var itemsArray = new Array();

    <{foreach from=$items item=item}>

    itemsArray.push('<{$item.barcode}>');

    <{/foreach}>

function filter($code) {

    var i, bn, all, num;

    for (i=0; i<itemsArray.length; i++) {

        bn = itemsArray[i];

        if ($code == 'all') {

            setborder('all');

            $('_' + bn).style.display = '';

        } else {

            num =  parseInt($(bn+"_num").get('text'));

            all = parseInt($(bn+"_all").get('text'));

            if ($code == 'finish') {

                setborder('finish');

                $('_' + bn).style.display = (num == all) ? '' : 'none';

            } else {

                setborder('');

                $('_' + bn).style.display = (num < all) ? '' : 'none';

            }

        }

    }

}

function setborder(code) {
    if (code == 'all') {
        $('allLink').set('styles', {'border':'1px solid','background-color':'#eeeeee', 'padding':'3px 10px', 'color':'black'});

        $('processLink').set('style', {});

        $('finishLink').set('style', {});

        //play($('soundControl'), '/public/sound/chimes.wav');

    } else if (code =='finish') {

        $('finishLink').set('styles', {'border':'1px solid','background-color':'#eeeeee', 'padding':'3px 10px', 'color':'black'});

        $('processLink').set('style', {});

        $('allLink').set('style', {});

    } else {

        $('processLink').set('styles', {'border':'1px solid','background-color':'#eeeeee', 'padding':'3px 10px', 'color':'black'});

        $('allLink').set('style', {});

        $('finishLink').set('style', {});

    }

}

</script>
<div class="spage-main-box">
<div class="tableform">

<div style="display: none;"><button class="btn" type="button" id="backbtn" onclick="new Dialog('index.php?app=ome&ctl=admin_check&act=showmemo&p[0]=<{$dly.delivery_id}>',{title:'打回发货单备注',width:600,height:500})"><span><span>打回此发货单</span></span></button></div>
        &nbsp;&nbsp;&nbsp;&nbsp;
<!-- <button class="btn" type="submit" onclick="return checkin();"><span><span>暂存已扫描数据</span></span></button>  -->

<a id="allLink" color='#333333' href='javascript:;' onclick='return filter("all");'>全部</a>&nbsp;&nbsp;
<a id="processLink" color='green' href='javascript:;' onclick='return filter("");'>待较验</a>&nbsp;&nbsp;
<a id="finishLink" color='red' href='javascript:;' onclick='return filter("finish");'>已较验</a>

<h3>校验明细</h3>
<div class="division">
<input type="hidden" id="tmp_bn" name="tmp_bn" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
                    <th style="font-size: 16px; font-weight: 700">请扫描商品条形码：</th>
                    <td><{input type="text" name="bn" id="bn"}>&nbsp;
                        <span style="font-size:14px" id='mess'>&nbsp;&nbsp;需要扫描 <b><font color='#333333'><{$count}></font></b> 个&nbsp;&nbsp;
                            &nbsp;&nbsp;已扫描 <b><font color="green"><{$verify_num}></font></b> 个&nbsp;&nbsp;
                            &nbsp;&nbsp;还需扫描 <b><font color="red"><{$remain}></font></b> 个&nbsp;&nbsp;</span>
                        <br>
    </td>
  </tr>
  <!--TR_HACK-->
</table>
</div>
        <div id="goodsMsg" class="gridlist" style="height: 60px; background-color: #F5F8F9; padding-top: 8px;text-indent: 15px; display:none;">
            &nbsp;&nbsp;&nbsp;商品名称：
            <span id="msgGoodsName" style="font-size: 14px; font-weight: 700;"></span>
            <span style="float:right; margin-right: 20px; color: red;">未扫描 <em id="msgTotalNum"></em> 个</span>
            <span style="float:right; margin-right: 20px; color: green;">已扫描 <em id="msgFinshNum"></em> 个</span>
            <div id="inputNumDiv" style="margin-top:8px; margin-left: 15px;">
            <span id="ipt_title" style="font-size: 12px; font-weight: 700;">数量：</span>
            &nbsp;<input id="ipt_num" type="text" value="" size="5"/>&nbsp;
            <font id="messs" color="red">如此项货物的数量较多并可保证数据的准确，可在此填入未扫描的数量，默认为所有未扫描数量，按回车提交。</font></div>
        </div>
        <br>
        <form name="form1" id="form1" method="POST" action="index.php?app=ome&ctl=admin_check&act=doCheck">
<h3 style="border-bottom:none">商品信息</h3>
<div class="gridlist">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
    <th >货号:</th>
    <th >条形码:</th>
    <th >货品名称:</th>
    <th >货品规格:</th>
    <th >货品数量:</th>
    <th >已校验数:</th>
</tr>
</thead>
<tbody>
<{foreach from=$items item=item}>
<tr id="_<{$item.barcode}>">
    <td><{$item.bn}> <input type="hidden" id="number_<{$item.barcode}>" name="number_<{$item.barcode}>" value="<{$item.verify_num}>" /> </td>
    <td><div id="<{$item.barcode}>"><{$item.barcode}></div></td>
    <td><div id="<{$item.barcode}>_name" style="color:<{$item.nameColor}>"><{$item.product_name}></div></td>
    <td><{$item.spec_info}></td>
    <!--TD_<{$item.barcode}>-->
    <td><font color="red"><div id="<{$item.barcode}>_all"><{$item.number}></font></td>
    <td><font color="green"><div id="<{$item.barcode}>_num"><{$item.verify_num}></div></font></td>
</tr>
<{/foreach}>
</tbody>
</table>
</div>
<input type="hidden" name="delivery_id" value="<{$dly.delivery_id}>" />
<input type="hidden" id="count" name="count" value="<{$count}>" />
<input type="hidden" id="number" name="number" value="<{$number}>" />
<input type="hidden" id="return" name="return" value="" />

<input type="hidden" vtype="required" name="logi_no" value="<{$dly.logi_no}>"/>
<!--
<div class="division">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th>
请录入快递单号：
</th>
<td>
</td>
</tr>
</table>
 -->

</div>


<div class="table-action">
<{button label="提交" class="btn-primary" id="logi_no" type="button" onclick="checkin()"}>
</div>
</form>

</div>
</div>